package com.culturalCenter.dataCenter.service.impl.training;

import com.culturalCenter.dataCenter.customEntity.responseParam.training.TrainingResourceResponse;
import com.culturalCenter.dataCenter.entity.training.TrainingResource;
import com.culturalCenter.dataCenter.entity.training.TrainingResourceCount;
import com.culturalCenter.dataCenter.mapper.training.TrainingResourceCountMapper;
import com.culturalCenter.dataCenter.mapper.training.TrainingResourceMapper;
import com.culturalCenter.dataCenter.service.training.TrainingResourceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : weicai
 * @date : 10:43 2020/10/26
 */
@Service
public class TrainingResourceServiceImpl implements TrainingResourceService {

    @Resource
    private TrainingResourceMapper trainingResourceMapper;
    @Resource
    private TrainingResourceCountMapper trainingResourceCountMapper;

    @Override
    public TrainingResourceResponse getPictureAndVideo(String trainingId, int pageNum, int pageSize) {
        TrainingResourceResponse trainingResourceResponse = new TrainingResourceResponse();
        PageHelper.startPage(pageNum, pageSize);
        List<TrainingResource> pictureAndVideoList = trainingResourceMapper.queryAllByTrainingId(trainingId, pageNum, pageSize);
        PageInfo<TrainingResource> pageInfo = new PageInfo<>(pictureAndVideoList);
        trainingResourceResponse.setPictureAndVideoList(pageInfo);
        List<TrainingResourceCount> resourceRatio = trainingResourceCountMapper.queryAllByTrainingId(trainingId);
        if (CollectionUtils.isNotEmpty(resourceRatio)) {
            trainingResourceResponse.setResourceRatio(resourceRatio);
        }

        return trainingResourceResponse;
    }

}
